package com.fy.fyrestfulapispringbootstartersample.controller;

import com.fy.fyrestfulapispringbootstartersample.entity.Student;
import com.fy.fyrestfulapispringbootstartersample.exception.UnknownErrorException;
import com.fy.redis.RedisHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author sunlei
 */
@Slf4j
@RestController
//@IgnoreUnifiedRESTful
public class TestController {
    @Autowired
    private RedisHelper redisHelper;
    @GetMapping("/info")
    public Student getUserInfo(@RequestParam(required = true) String name, Integer age) {
        Student s = new Student();
        s.setName("枫叶");
        s.setAge(18);
        s.setSex("male");

        redisHelper.set("test1", s);

        Object obj = redisHelper.get("test1");
        log.error("________redis____:" + obj.toString());

        return s;
    }

//    @IgnoreUnifiedRESTful
    @GetMapping("/infotest")
    public String getUserInfoErr(@RequestParam(required = true) String name, Integer age) {
        Student s = new Student();
        s.setName("枫叶");
        s.setAge(18);
        s.setSex("male");

        if (s != null) {
            throw new UnknownErrorException("未知异常啊");
        }

        return "";
    }
}
